<!-- 提现服务主页面 -->
<template>
	<view class="wp">
		<view class="header">
			<view class="txt-xh">
				<view class="h3">
					￥{{money}}
				</view>
				<text>可提现金额(元)</text>
				
			</view>
		</view>
		<view class="boe">
			<view class="m-about">
				<view class="h3">
					提现金额
				</view>
				<view class="num">
					<view class="desc">￥</view> <text>每日最高提现</text>
					<input class="inp" placeholder="请输出金额" type="number" v-model="moneyvalue">

				</view>
				<view class="boe">
					<text>提现至</text>
					<text class="s1">微信零钱</text>
				</view>
				<view class="g-queding-kx" @click="tixian">
					<view class="txt">
						<view class="s1">提现</view>
					</view>
				</view>
			</view>
		</view>
		<view class="main">
			<view class="txt-xh1">
				<view class="tit">
					<view class="h3">
						说明：
					</view>
					<view class="info">
						1.<text>提现规则</text>：提现的受益自动到微信零钱
					</view>
					<view class="info">
						2.<text>到账时间</text>：提现成功后待管理员审核后24小时之内到账
					</view>
					<view class="info">
						3.<text>提现金额</text>：提现金额必须是整数，否则提现失败
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {http} from "../static/service/requestAddress/rtas.js"
	import bignumber from "bignumber.js"
	export default {
		data() {
			return {
				money:"",
				moneyvalue:"",
			}
		},
		onShow(){
			if(uni.getStorageSync("user")){
				uni.request({
					url:http+"user/money/"+JSON.parse(uni.getStorageSync("user")).id,
					method:"GET",
					complete:(res)=>{
						if(res.data.code == 20021){
							this.money = res.data.date
							uni.$u.toast("获取用户金额成功")
						}
					}
				})
			}else{
				uni.$u.toast("登录后才能获取金额喔")
			}
		},
		methods:{
			tixian(){
				var num1 =  bignumber(this.money)//用户金额
				var num2 = bignumber(this.moneyvalue)//提现金额
				if(num1.minus(num2) < 0){
					uni.$u.toast("最大提现不能超过余额")
					return
				} 
				var userid = JSON.parse(uni.getStorageSync("user")).id
				var oppid = ""
				var money = num2
				uni.login({
					success(res) {
						uni.request({
							url: http+"wxlogin/"+res.code,
							method:"GET",
							success(res) {
								oppid = res.data.date
								console.log("获取oppid成功:"+oppid)
								//发送提现请求
								uni.request({
									url:http+"wxpay/cashwithdrawal/"+userid+"/"+money+"/"+oppid,
									method:"POST",
									complete:(res)=>{
										if(res.data.code == 20011){
											uni.$u.toast("提现成功")
											this.money = ""+num1.minus(num2)
										}else{
											uni.$u.toast("提现失败")
										}
									}
								})
							},
							fail(res) {
								uni.$u.toast("获取code失败！")
							}
						})
					}
				})
				console.log("点击了提现"+this.moneyvalue)
			}
		}
	}
</script>
<style>
	@import url("../static/css/componentsCss/tixian/index.css");
</style>